package com.csc.bankingsystem.core.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

/**
 * UserInfo Data Transfer Object
 * 
 * @author angelkid
 *
 */
@Entity
@Table(name = "USERINFO")
public class UserInfo extends BankingSystemAbstractEntity {
	private String loginId;
	private String password;
	private boolean enabled;
	private Date lastVisit;
	private Integer numAttempt = 0;
	private String salt;
	// Reference Data
	private List<UserInfoRole> userInfoRoles;
	private List<AccountInfo> accountInfos;
	private TokenRecord tokenRecord;

	@Column(name = "loginId", unique = true, nullable = false, length = 50)
	public String getLoginId() {
		return loginId;
	}

	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}

	@Column(name = "password", unique = false, nullable = false, length = 50)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "enabled", unique = false, nullable = false, length = 12)
	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	@Column(name = "lastVisit")
	public Date getLastVisit() {
		return lastVisit;
	}

	public void setLastVisit(Date lastVisit) {
		this.lastVisit = lastVisit;
	}

	@Column(name = "numAttempt")
	public Integer getNumAttempt() {
		return numAttempt;
	}

	public void setNumAttempt(Integer numAttempt) {
		this.numAttempt = numAttempt;
	}

	@Column(name="salt")
	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	// ,cascade=CascadeType.ALL
	@JsonBackReference
	@OneToMany(mappedBy = "userInfo")
	public List<UserInfoRole> getUserInfoRoles() {
		return userInfoRoles;
	}

	public void setUserInfoRoles(List<UserInfoRole> userInfoRoles) {
		this.userInfoRoles = userInfoRoles;
	}

	@JsonBackReference
	@OneToMany(mappedBy = "userInfo")
	public List<AccountInfo> getAccountInfos() {
		return accountInfos;
	}

	public void setAccountInfos(List<AccountInfo> accountInfos) {
		this.accountInfos = accountInfos;
	}

	@JsonBackReference
	@OneToOne(mappedBy = "userInfo")
	public TokenRecord getTokenRecord() {
		return tokenRecord;
	}

	public void setTokenRecord(TokenRecord tokenRecord) {
		this.tokenRecord = tokenRecord;
	}

	@Override
	public String toString() {
		return "UserInfoDTO [id=" + id + ", loginId=" + loginId + ", password="
				+ password + ", enabled=" + enabled + "]";
	}

}
